@dxos/react-ui-editor 0.8.3-main.7f5a14c → 0.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/index.mjs +371 -375
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +502 -511
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +371 -375
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/EditorToolbar/EditorToolbar.d.ts.map +1 -1
- package/dist/types/src/components/Popover/RefDropdownMenu.d.ts.map +1 -1
- package/dist/types/src/components/Popover/RefPopover.d.ts.map +1 -1
- package/dist/types/src/defaults.d.ts +0 -1
- package/dist/types/src/defaults.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/automerge.stories.d.ts.map +1 -1
- package/dist/types/src/extensions/command/action.d.ts.map +1 -1
- package/dist/types/src/extensions/command/command-menu.d.ts +20 -0
- package/dist/types/src/extensions/command/command-menu.d.ts.map +1 -0
- package/dist/types/src/extensions/command/command.d.ts.map +1 -1
- package/dist/types/src/extensions/command/floating-menu.d.ts +7 -0
- package/dist/types/src/extensions/command/floating-menu.d.ts.map +1 -0
- package/dist/types/src/extensions/command/hint.d.ts +5 -2
- package/dist/types/src/extensions/command/hint.d.ts.map +1 -1
- package/dist/types/src/extensions/command/index.d.ts +3 -1
- package/dist/types/src/extensions/command/index.d.ts.map +1 -1
- package/dist/types/src/extensions/command/placeholder.d.ts +10 -0
- package/dist/types/src/extensions/command/placeholder.d.ts.map +1 -0
- package/dist/types/src/extensions/command/state.d.ts +1 -1
- package/dist/types/src/extensions/command/state.d.ts.map +1 -1
- package/dist/types/src/extensions/command/useCommandMenu.d.ts +26 -0
- package/dist/types/src/extensions/command/useCommandMenu.d.ts.map +1 -0
- package/dist/types/src/extensions/index.d.ts +0 -1
- package/dist/types/src/extensions/index.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
- package/dist/types/src/extensions/outliner/tree.d.ts.map +1 -1
- package/dist/types/src/extensions/preview/preview.d.ts +12 -19
- package/dist/types/src/extensions/preview/preview.d.ts.map +1 -1
- package/dist/types/src/stories/CommandMenu.stories.d.ts +5 -4
- package/dist/types/src/stories/CommandMenu.stories.d.ts.map +1 -1
- package/dist/types/src/stories/Preview.stories.d.ts.map +1 -1
- package/dist/types/src/util/dom.d.ts +5 -0
- package/dist/types/src/util/dom.d.ts.map +1 -1
- package/dist/types/src/util/react.d.ts +2 -4
- package/dist/types/src/util/react.d.ts.map +1 -1
- package/package.json +31 -31
- package/src/components/EditorToolbar/EditorToolbar.tsx +5 -9
- package/src/components/Popover/RefDropdownMenu.tsx +5 -3
- package/src/components/Popover/RefPopover.tsx +5 -3
- package/src/defaults.ts +0 -6
- package/src/extensions/automerge/automerge.stories.tsx +5 -5
- package/src/extensions/command/action.ts +9 -2
- package/src/extensions/command/command-menu.ts +210 -0
- package/src/extensions/command/command.ts +8 -8
- package/src/extensions/command/floating-menu.ts +133 -0
- package/src/extensions/command/hint.ts +29 -9
- package/src/extensions/command/index.ts +3 -1
- package/src/extensions/command/placeholder.ts +113 -0
- package/src/extensions/command/state.ts +1 -2
- package/src/extensions/command/useCommandMenu.ts +118 -0
- package/src/extensions/index.ts +0 -1
- package/src/extensions/markdown/bundle.ts +0 -2
- package/src/extensions/outliner/tree.test.ts +13 -10
- package/src/extensions/outliner/tree.ts +5 -3
- package/src/extensions/preview/preview.ts +11 -86
- package/src/stories/Command.stories.tsx +1 -1
- package/src/stories/CommandMenu.stories.tsx +35 -19
- package/src/stories/Preview.stories.tsx +134 -57
- package/src/stories/components/util.tsx +2 -2
- package/src/util/dom.ts +20 -0
- package/src/util/react.tsx +3 -20
- package/dist/types/src/extensions/command/menu.d.ts +0 -47
- package/dist/types/src/extensions/command/menu.d.ts.map +0 -1
- package/dist/types/src/extensions/placeholder.d.ts +0 -4
- package/dist/types/src/extensions/placeholder.d.ts.map +0 -1
- package/src/extensions/command/menu.ts +0 -439
- package/src/extensions/placeholder.ts +0 -82
@@ -35,7 +35,7 @@ var translations_default = [
|
|
35
35
|
|
36
36
|
// packages/ui/react-ui-editor/src/index.ts
|
37
37
|
import { EditorState as EditorState4 } from "@codemirror/state";
|
38
|
-
import { EditorView as
|
38
|
+
import { EditorView as EditorView27, keymap as keymap14 } from "@codemirror/view";
|
39
39
|
import { tags as tags2 } from "@lezer/highlight";
|
40
40
|
import { TextKind } from "@dxos/protocols/proto/dxos/echo/model/text";
|
41
41
|
|
@@ -46,7 +46,6 @@ import React3, { memo, useMemo as useMemo4 } from "react";
|
|
46
46
|
import { rxFromSignal } from "@dxos/app-graph";
|
47
47
|
import { ElevationProvider } from "@dxos/react-ui";
|
48
48
|
import { MenuProvider, ToolbarMenu, createGapSeparator, useMenuActions } from "@dxos/react-ui-menu";
|
49
|
-
import { textBlockWidth } from "@dxos/react-ui-theme";
|
50
49
|
|
51
50
|
// packages/ui/react-ui-editor/src/components/EditorToolbar/util.ts
|
52
51
|
import { useMemo } from "react";
|
@@ -517,17 +516,14 @@ var clientRectsFor = (dom) => {
|
|
517
516
|
return [];
|
518
517
|
}
|
519
518
|
};
|
520
|
-
|
521
|
-
// packages/ui/react-ui-editor/src/util/react.tsx
|
522
|
-
import React from "react";
|
523
|
-
import { createRoot } from "react-dom/client";
|
524
|
-
import { ThemeProvider, Tooltip } from "@dxos/react-ui";
|
525
|
-
import { defaultTx } from "@dxos/react-ui-theme";
|
526
519
|
var createElement = (tag, options, children) => {
|
527
520
|
const el = document.createElement(tag);
|
528
521
|
if (options?.className) {
|
529
522
|
el.className = options.className;
|
530
523
|
}
|
524
|
+
if (options?.text) {
|
525
|
+
el.textContent = options.text;
|
526
|
+
}
|
531
527
|
if (children) {
|
532
528
|
el.append(...Array.isArray(children) ? children : [
|
533
529
|
children
|
@@ -535,6 +531,12 @@ var createElement = (tag, options, children) => {
|
|
535
531
|
}
|
536
532
|
return el;
|
537
533
|
};
|
534
|
+
|
535
|
+
// packages/ui/react-ui-editor/src/util/react.tsx
|
536
|
+
import React from "react";
|
537
|
+
import { createRoot } from "react-dom/client";
|
538
|
+
import { ThemeProvider, Tooltip } from "@dxos/react-ui";
|
539
|
+
import { defaultTx } from "@dxos/react-ui-theme";
|
538
540
|
var renderRoot = (root, node) => {
|
539
541
|
createRoot(root).render(/* @__PURE__ */ React.createElement(ThemeProvider, {
|
540
542
|
tx: defaultTx
|
@@ -1358,6 +1360,7 @@ var closeCommand = (view) => {
|
|
1358
1360
|
var commandKeyBindings = [
|
1359
1361
|
{
|
1360
1362
|
key: "/",
|
1363
|
+
preventDefault: true,
|
1361
1364
|
run: openCommand
|
1362
1365
|
},
|
1363
1366
|
{
|
@@ -1367,37 +1370,55 @@ var commandKeyBindings = [
|
|
1367
1370
|
];
|
1368
1371
|
|
1369
1372
|
// packages/ui/react-ui-editor/src/extensions/command/command.ts
|
1373
|
+
import { Prec } from "@codemirror/state";
|
1370
1374
|
import { EditorView as EditorView6, keymap as keymap3 } from "@codemirror/view";
|
1375
|
+
import { isNonNullable } from "@dxos/util";
|
1371
1376
|
|
1372
1377
|
// packages/ui/react-ui-editor/src/extensions/command/hint.ts
|
1373
1378
|
import { RangeSetBuilder as RangeSetBuilder2 } from "@codemirror/state";
|
1374
1379
|
import { Decoration as Decoration3, EditorView as EditorView5, ViewPlugin as ViewPlugin4, WidgetType as WidgetType2 } from "@codemirror/view";
|
1375
|
-
var
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1380
|
+
var hint = ({ delay = 3e3, onHint }) => {
|
1381
|
+
return ViewPlugin4.fromClass(class {
|
1382
|
+
constructor() {
|
1383
|
+
this.decorations = Decoration3.none;
|
1384
|
+
}
|
1385
|
+
update(update2) {
|
1386
|
+
if (this.timeout) {
|
1387
|
+
clearTimeout(this.timeout);
|
1388
|
+
this.timeout = void 0;
|
1389
|
+
}
|
1390
|
+
const builder = new RangeSetBuilder2();
|
1391
|
+
const cState = update2.view.state.field(commandState, false);
|
1392
|
+
if (!cState?.tooltip) {
|
1393
|
+
const selection = update2.view.state.selection.main;
|
1394
|
+
const line = update2.view.state.doc.lineAt(selection.from);
|
1395
|
+
if (selection.from === selection.to && line.from === line.to) {
|
1396
|
+
this.timeout = setTimeout(() => {
|
1397
|
+
const hint2 = onHint?.();
|
1398
|
+
if (hint2) {
|
1399
|
+
const builder2 = new RangeSetBuilder2();
|
1400
|
+
builder2.add(selection.from, selection.to, Decoration3.widget({
|
1401
|
+
widget: new Hint(hint2)
|
1402
|
+
}));
|
1403
|
+
this.decorations = builder2.finish();
|
1404
|
+
update2.view.update([]);
|
1405
|
+
}
|
1406
|
+
}, delay);
|
1391
1407
|
}
|
1392
1408
|
}
|
1409
|
+
this.decorations = builder.finish();
|
1393
1410
|
}
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1411
|
+
destroy() {
|
1412
|
+
if (this.timeout) {
|
1413
|
+
clearTimeout(this.timeout);
|
1414
|
+
}
|
1415
|
+
}
|
1416
|
+
}, {
|
1417
|
+
provide: (plugin) => [
|
1418
|
+
EditorView5.decorations.of((view) => view.plugin(plugin)?.decorations ?? Decoration3.none)
|
1419
|
+
]
|
1420
|
+
});
|
1421
|
+
};
|
1401
1422
|
var Hint = class extends WidgetType2 {
|
1402
1423
|
constructor(content) {
|
1403
1424
|
super(), this.content = content;
|
@@ -1440,31 +1461,70 @@ var Hint = class extends WidgetType2 {
|
|
1440
1461
|
// packages/ui/react-ui-editor/src/extensions/command/command.ts
|
1441
1462
|
var command = (options = {}) => {
|
1442
1463
|
return [
|
1443
|
-
keymap3.of(commandKeyBindings),
|
1464
|
+
Prec.highest(keymap3.of(commandKeyBindings)),
|
1444
1465
|
commandConfig.of(options),
|
1445
1466
|
commandState,
|
1446
|
-
options.onHint
|
1447
|
-
|
1448
|
-
}) : [],
|
1449
|
-
EditorView6.focusChangeEffect.of((_, focusing) => {
|
1450
|
-
return focusing ? closeEffect.of(null) : null;
|
1451
|
-
}),
|
1467
|
+
options.onHint && hint(options),
|
1468
|
+
EditorView6.focusChangeEffect.of((_, focusing) => focusing ? closeEffect.of(null) : null),
|
1452
1469
|
EditorView6.theme({
|
1453
1470
|
".cm-tooltip": {
|
1454
1471
|
background: "transparent"
|
1455
1472
|
}
|
1456
1473
|
})
|
1457
|
-
];
|
1474
|
+
].filter(isNonNullable);
|
1458
1475
|
};
|
1459
1476
|
|
1460
|
-
// packages/ui/react-ui-editor/src/extensions/command/menu.ts
|
1461
|
-
import { RangeSetBuilder as RangeSetBuilder3, StateField as StateField3, StateEffect as StateEffect3, Prec } from "@codemirror/state";
|
1477
|
+
// packages/ui/react-ui-editor/src/extensions/command/command-menu.ts
|
1478
|
+
import { RangeSetBuilder as RangeSetBuilder3, StateField as StateField3, StateEffect as StateEffect3, Prec as Prec2 } from "@codemirror/state";
|
1462
1479
|
import { EditorView as EditorView8, ViewPlugin as ViewPlugin6, Decoration as Decoration5, keymap as keymap4 } from "@codemirror/view";
|
1463
|
-
import { useCallback, useMemo as useMemo2, useRef, useState } from "react";
|
1464
|
-
import { addEventListener } from "@dxos/async";
|
1465
1480
|
|
1466
|
-
// packages/ui/react-ui-editor/src/extensions/placeholder.ts
|
1481
|
+
// packages/ui/react-ui-editor/src/extensions/command/placeholder.ts
|
1467
1482
|
import { Decoration as Decoration4, EditorView as EditorView7, WidgetType as WidgetType3, ViewPlugin as ViewPlugin5 } from "@codemirror/view";
|
1483
|
+
var placeholder = ({ delay = 3e3, content }) => {
|
1484
|
+
const plugin = ViewPlugin5.fromClass(class {
|
1485
|
+
constructor() {
|
1486
|
+
this.decorations = Decoration4.none;
|
1487
|
+
}
|
1488
|
+
update(update2) {
|
1489
|
+
if (this.timeout) {
|
1490
|
+
window.clearTimeout(this.timeout);
|
1491
|
+
this.timeout = void 0;
|
1492
|
+
}
|
1493
|
+
const activeLine = update2.view.state.doc.lineAt(update2.view.state.selection.main.head);
|
1494
|
+
const isEmpty = activeLine.text.trim() === "";
|
1495
|
+
if (isEmpty) {
|
1496
|
+
const lineStart = activeLine.from;
|
1497
|
+
this.timeout = setTimeout(() => {
|
1498
|
+
this.decorations = Decoration4.set([
|
1499
|
+
Decoration4.widget({
|
1500
|
+
widget: new Placeholder(content),
|
1501
|
+
side: 1
|
1502
|
+
}).range(lineStart)
|
1503
|
+
]);
|
1504
|
+
update2.view.update([]);
|
1505
|
+
}, delay);
|
1506
|
+
}
|
1507
|
+
this.decorations = Decoration4.none;
|
1508
|
+
}
|
1509
|
+
destroy() {
|
1510
|
+
if (this.timeout) {
|
1511
|
+
clearTimeout(this.timeout);
|
1512
|
+
}
|
1513
|
+
}
|
1514
|
+
}, {
|
1515
|
+
provide: (plugin2) => {
|
1516
|
+
return [
|
1517
|
+
EditorView7.decorations.of((view) => view.plugin(plugin2)?.decorations ?? Decoration4.none)
|
1518
|
+
];
|
1519
|
+
}
|
1520
|
+
});
|
1521
|
+
return typeof content === "string" ? [
|
1522
|
+
plugin,
|
1523
|
+
EditorView7.contentAttributes.of({
|
1524
|
+
"aria-placeholder": content
|
1525
|
+
})
|
1526
|
+
] : plugin;
|
1527
|
+
};
|
1468
1528
|
var Placeholder = class extends WidgetType3 {
|
1469
1529
|
constructor(content) {
|
1470
1530
|
super(), this.content = content;
|
@@ -1499,135 +1559,8 @@ var Placeholder = class extends WidgetType3 {
|
|
1499
1559
|
return false;
|
1500
1560
|
}
|
1501
1561
|
};
|
1502
|
-
function multilinePlaceholder(content) {
|
1503
|
-
const plugin = ViewPlugin5.fromClass(class {
|
1504
|
-
constructor(view) {
|
1505
|
-
this.view = view;
|
1506
|
-
}
|
1507
|
-
get decorations() {
|
1508
|
-
const activeLine = this.view.state.doc.lineAt(this.view.state.selection.main.head);
|
1509
|
-
const isEmpty = activeLine.text.trim() === "";
|
1510
|
-
if (!isEmpty || !content) {
|
1511
|
-
return Decoration4.none;
|
1512
|
-
}
|
1513
|
-
const lineStart = activeLine.from;
|
1514
|
-
return Decoration4.set([
|
1515
|
-
Decoration4.widget({
|
1516
|
-
widget: new Placeholder(content),
|
1517
|
-
side: 1
|
1518
|
-
}).range(lineStart)
|
1519
|
-
]);
|
1520
|
-
}
|
1521
|
-
}, {
|
1522
|
-
decorations: (v) => v.decorations
|
1523
|
-
});
|
1524
|
-
return typeof content === "string" ? [
|
1525
|
-
plugin,
|
1526
|
-
EditorView7.contentAttributes.of({
|
1527
|
-
"aria-placeholder": content
|
1528
|
-
})
|
1529
|
-
] : plugin;
|
1530
|
-
}
|
1531
1562
|
|
1532
|
-
// packages/ui/react-ui-editor/src/extensions/command/menu.ts
|
1533
|
-
var floatingMenu = (options = {}) => [
|
1534
|
-
ViewPlugin6.fromClass(class {
|
1535
|
-
constructor(view) {
|
1536
|
-
this.view = view;
|
1537
|
-
const container = view.scrollDOM;
|
1538
|
-
if (getComputedStyle(container).position === "static") {
|
1539
|
-
container.style.position = "relative";
|
1540
|
-
}
|
1541
|
-
{
|
1542
|
-
const icon = document.createElement("dx-icon");
|
1543
|
-
icon.setAttribute("icon", options.icon ?? "ph--dots-three-vertical--regular");
|
1544
|
-
const button = document.createElement("button");
|
1545
|
-
button.appendChild(icon);
|
1546
|
-
this.tag = document.createElement("dx-ref-tag");
|
1547
|
-
this.tag.classList.add("cm-ref-tag");
|
1548
|
-
this.tag.appendChild(button);
|
1549
|
-
}
|
1550
|
-
container.appendChild(this.tag);
|
1551
|
-
const handler = () => this.scheduleUpdate();
|
1552
|
-
this.cleanup = addEventListener(container, "scroll", handler);
|
1553
|
-
this.scheduleUpdate();
|
1554
|
-
}
|
1555
|
-
destroy() {
|
1556
|
-
this.cleanup?.();
|
1557
|
-
this.tag.remove();
|
1558
|
-
if (this.rafId != null) {
|
1559
|
-
cancelAnimationFrame(this.rafId);
|
1560
|
-
}
|
1561
|
-
}
|
1562
|
-
update(update2) {
|
1563
|
-
this.tag.dataset.focused = update2.view.hasFocus ? "true" : "false";
|
1564
|
-
if (!update2.view.hasFocus) {
|
1565
|
-
return;
|
1566
|
-
}
|
1567
|
-
if (update2.transactions.some((tr) => tr.effects.some((effect) => effect.is(openEffect)))) {
|
1568
|
-
this.tag.style.display = "none";
|
1569
|
-
this.tag.classList.add("opacity-10");
|
1570
|
-
} else if (update2.transactions.some((tr) => tr.effects.some((effect) => effect.is(closeEffect)))) {
|
1571
|
-
this.tag.style.display = "block";
|
1572
|
-
} else if (update2.docChanged || update2.focusChanged || update2.geometryChanged || update2.selectionSet || update2.viewportChanged) {
|
1573
|
-
this.scheduleUpdate();
|
1574
|
-
}
|
1575
|
-
}
|
1576
|
-
updateButtonPosition() {
|
1577
|
-
const { x, width } = this.view.contentDOM.getBoundingClientRect();
|
1578
|
-
const pos = this.view.state.selection.main.head;
|
1579
|
-
const line = this.view.lineBlockAt(pos);
|
1580
|
-
const coords = this.view.coordsAtPos(line.from);
|
1581
|
-
if (!coords) {
|
1582
|
-
return;
|
1583
|
-
}
|
1584
|
-
const lineHeight = coords.bottom - coords.top;
|
1585
|
-
const dy = (lineHeight - (options.height ?? 32)) / 2;
|
1586
|
-
const offsetTop = coords.top + dy;
|
1587
|
-
const offsetLeft = x + width + (options.padding ?? 8);
|
1588
|
-
this.tag.style.top = `${offsetTop}px`;
|
1589
|
-
this.tag.style.left = `${offsetLeft}px`;
|
1590
|
-
this.tag.style.display = "block";
|
1591
|
-
}
|
1592
|
-
scheduleUpdate() {
|
1593
|
-
if (this.rafId != null) {
|
1594
|
-
cancelAnimationFrame(this.rafId);
|
1595
|
-
}
|
1596
|
-
this.rafId = requestAnimationFrame(this.updateButtonPosition.bind(this));
|
1597
|
-
}
|
1598
|
-
}),
|
1599
|
-
EditorView8.theme({
|
1600
|
-
".cm-ref-tag": {
|
1601
|
-
position: "fixed",
|
1602
|
-
padding: "0",
|
1603
|
-
border: "none",
|
1604
|
-
opacity: "0"
|
1605
|
-
},
|
1606
|
-
"[data-has-focus] & .cm-ref-tag": {
|
1607
|
-
opacity: "1"
|
1608
|
-
},
|
1609
|
-
".cm-ref-tag button": {
|
1610
|
-
display: "grid",
|
1611
|
-
alignItems: "center",
|
1612
|
-
justifyContent: "center",
|
1613
|
-
width: "2rem",
|
1614
|
-
height: "2rem"
|
1615
|
-
}
|
1616
|
-
})
|
1617
|
-
];
|
1618
|
-
var commandRangeEffect = StateEffect3.define();
|
1619
|
-
var commandMenuState = StateField3.define({
|
1620
|
-
create: () => null,
|
1621
|
-
update: (value, tr) => {
|
1622
|
-
let newValue = value;
|
1623
|
-
for (const effect of tr.effects) {
|
1624
|
-
if (effect.is(commandRangeEffect)) {
|
1625
|
-
newValue = effect.value;
|
1626
|
-
}
|
1627
|
-
}
|
1628
|
-
return newValue;
|
1629
|
-
}
|
1630
|
-
});
|
1563
|
+
// packages/ui/react-ui-editor/src/extensions/command/command-menu.ts
|
1631
1564
|
var commandMenu = (options) => {
|
1632
1565
|
const commandMenuPlugin = ViewPlugin6.fromClass(class {
|
1633
1566
|
constructor(view) {
|
@@ -1666,11 +1599,11 @@ var commandMenu = (options) => {
|
|
1666
1599
|
const commandKeymap = keymap4.of([
|
1667
1600
|
...triggers.map((trigger) => ({
|
1668
1601
|
key: trigger,
|
1602
|
+
preventDefault: true,
|
1669
1603
|
run: (view) => {
|
1670
1604
|
const selection = view.state.selection.main;
|
1671
1605
|
const line = view.state.doc.lineAt(selection.head);
|
1672
|
-
|
1673
|
-
if (shouldTrigger) {
|
1606
|
+
if (line.text.trim() === "" || selection.head === line.from || selection.head > line.from && line.text[selection.head - line.from - 1] === " ") {
|
1674
1607
|
view.dispatch({
|
1675
1608
|
changes: {
|
1676
1609
|
from: selection.head,
|
@@ -1757,27 +1690,134 @@ var commandMenu = (options) => {
|
|
1757
1690
|
});
|
1758
1691
|
}
|
1759
1692
|
if (shouldRemove) {
|
1760
|
-
options.
|
1693
|
+
options.onClose?.();
|
1761
1694
|
}
|
1762
1695
|
});
|
1763
1696
|
return [
|
1764
|
-
|
1765
|
-
|
1697
|
+
Prec2.highest(commandKeymap),
|
1698
|
+
placeholder(Object.assign({
|
1699
|
+
content: `Press '${Array.isArray(options.trigger) ? options.trigger[0] : options.trigger}' for commands`
|
1700
|
+
}, options.placeholder)),
|
1766
1701
|
updateListener,
|
1767
1702
|
commandMenuState,
|
1768
1703
|
commandMenuPlugin
|
1769
1704
|
];
|
1770
1705
|
};
|
1771
|
-
var
|
1706
|
+
var commandRangeEffect = StateEffect3.define();
|
1707
|
+
var commandMenuState = StateField3.define({
|
1708
|
+
create: () => null,
|
1709
|
+
update: (value, tr) => {
|
1710
|
+
let newValue = value;
|
1711
|
+
for (const effect of tr.effects) {
|
1712
|
+
if (effect.is(commandRangeEffect)) {
|
1713
|
+
newValue = effect.value;
|
1714
|
+
}
|
1715
|
+
}
|
1716
|
+
return newValue;
|
1717
|
+
}
|
1718
|
+
});
|
1719
|
+
|
1720
|
+
// packages/ui/react-ui-editor/src/extensions/command/floating-menu.ts
|
1721
|
+
import { EditorView as EditorView9, ViewPlugin as ViewPlugin7 } from "@codemirror/view";
|
1722
|
+
import { addEventListener } from "@dxos/async";
|
1723
|
+
var floatingMenu = (options = {}) => [
|
1724
|
+
ViewPlugin7.fromClass(class {
|
1725
|
+
constructor(view) {
|
1726
|
+
this.view = view;
|
1727
|
+
const container = view.scrollDOM;
|
1728
|
+
if (getComputedStyle(container).position === "static") {
|
1729
|
+
container.style.position = "relative";
|
1730
|
+
}
|
1731
|
+
{
|
1732
|
+
const icon = document.createElement("dx-icon");
|
1733
|
+
icon.setAttribute("icon", options.icon ?? "ph--dots-three-vertical--regular");
|
1734
|
+
const button = document.createElement("button");
|
1735
|
+
button.appendChild(icon);
|
1736
|
+
this.tag = document.createElement("dx-ref-tag");
|
1737
|
+
this.tag.classList.add("cm-ref-tag");
|
1738
|
+
this.tag.appendChild(button);
|
1739
|
+
}
|
1740
|
+
container.appendChild(this.tag);
|
1741
|
+
const handler = () => this.scheduleUpdate();
|
1742
|
+
this.cleanup = addEventListener(container, "scroll", handler);
|
1743
|
+
this.scheduleUpdate();
|
1744
|
+
}
|
1745
|
+
destroy() {
|
1746
|
+
this.cleanup?.();
|
1747
|
+
this.tag.remove();
|
1748
|
+
if (this.rafId != null) {
|
1749
|
+
cancelAnimationFrame(this.rafId);
|
1750
|
+
}
|
1751
|
+
}
|
1752
|
+
update(update2) {
|
1753
|
+
this.tag.dataset.focused = update2.view.hasFocus ? "true" : "false";
|
1754
|
+
if (!update2.view.hasFocus) {
|
1755
|
+
return;
|
1756
|
+
}
|
1757
|
+
if (update2.transactions.some((tr) => tr.effects.some((effect) => effect.is(openEffect)))) {
|
1758
|
+
this.tag.style.display = "none";
|
1759
|
+
this.tag.classList.add("opacity-10");
|
1760
|
+
} else if (update2.transactions.some((tr) => tr.effects.some((effect) => effect.is(closeEffect)))) {
|
1761
|
+
this.tag.style.display = "block";
|
1762
|
+
} else if (update2.docChanged || update2.focusChanged || update2.geometryChanged || update2.selectionSet || update2.viewportChanged) {
|
1763
|
+
this.scheduleUpdate();
|
1764
|
+
}
|
1765
|
+
}
|
1766
|
+
updateButtonPosition() {
|
1767
|
+
const { x, width } = this.view.contentDOM.getBoundingClientRect();
|
1768
|
+
const pos = this.view.state.selection.main.head;
|
1769
|
+
const line = this.view.lineBlockAt(pos);
|
1770
|
+
const coords = this.view.coordsAtPos(line.from);
|
1771
|
+
if (!coords) {
|
1772
|
+
return;
|
1773
|
+
}
|
1774
|
+
const lineHeight = coords.bottom - coords.top;
|
1775
|
+
const dy = (lineHeight - (options.height ?? 32)) / 2;
|
1776
|
+
const offsetTop = coords.top + dy;
|
1777
|
+
const offsetLeft = x + width + (options.padding ?? 8);
|
1778
|
+
this.tag.style.top = `${offsetTop}px`;
|
1779
|
+
this.tag.style.left = `${offsetLeft}px`;
|
1780
|
+
this.tag.style.display = "block";
|
1781
|
+
}
|
1782
|
+
scheduleUpdate() {
|
1783
|
+
if (this.rafId != null) {
|
1784
|
+
cancelAnimationFrame(this.rafId);
|
1785
|
+
}
|
1786
|
+
this.rafId = requestAnimationFrame(this.updateButtonPosition.bind(this));
|
1787
|
+
}
|
1788
|
+
}),
|
1789
|
+
EditorView9.theme({
|
1790
|
+
".cm-ref-tag": {
|
1791
|
+
position: "fixed",
|
1792
|
+
padding: "0",
|
1793
|
+
border: "none",
|
1794
|
+
opacity: "0"
|
1795
|
+
},
|
1796
|
+
"[data-has-focus] & .cm-ref-tag": {
|
1797
|
+
opacity: "1"
|
1798
|
+
},
|
1799
|
+
".cm-ref-tag button": {
|
1800
|
+
display: "grid",
|
1801
|
+
alignItems: "center",
|
1802
|
+
justifyContent: "center",
|
1803
|
+
width: "2rem",
|
1804
|
+
height: "2rem"
|
1805
|
+
}
|
1806
|
+
})
|
1807
|
+
];
|
1808
|
+
|
1809
|
+
// packages/ui/react-ui-editor/src/extensions/command/useCommandMenu.ts
|
1810
|
+
import { useCallback, useMemo as useMemo2, useRef, useState } from "react";
|
1811
|
+
var useCommandMenu = ({ viewRef, trigger, placeholder: placeholder3, getMenu }) => {
|
1772
1812
|
const triggerRef = useRef(null);
|
1773
1813
|
const currentRef = useRef(null);
|
1774
1814
|
const groupsRef = useRef([]);
|
1775
1815
|
const [currentItem, setCurrentItem] = useState();
|
1776
1816
|
const [open, setOpen] = useState(false);
|
1777
|
-
const [_,
|
1817
|
+
const [_, refresh] = useState({});
|
1778
1818
|
const handleOpenChange = useCallback(async (open2, trigger2) => {
|
1779
1819
|
if (open2 && trigger2) {
|
1780
|
-
groupsRef.current = await
|
1820
|
+
groupsRef.current = await getMenu(trigger2);
|
1781
1821
|
}
|
1782
1822
|
setOpen(open2);
|
1783
1823
|
if (!open2) {
|
@@ -1790,7 +1830,7 @@ var useCommandMenu = ({ viewRef, trigger, placeholder: placeholder2, getGroups }
|
|
1790
1830
|
});
|
1791
1831
|
}
|
1792
1832
|
}, [
|
1793
|
-
|
1833
|
+
getMenu
|
1794
1834
|
]);
|
1795
1835
|
const handleActivate = useCallback(async (event) => {
|
1796
1836
|
const item = getItem(groupsRef.current, currentItem);
|
@@ -1815,43 +1855,45 @@ var useCommandMenu = ({ viewRef, trigger, placeholder: placeholder2, getGroups }
|
|
1815
1855
|
void item.onSelect?.(view, selection.head);
|
1816
1856
|
}, []);
|
1817
1857
|
const serializedTrigger = Array.isArray(trigger) ? trigger.join(",") : trigger;
|
1818
|
-
const _commandMenu = useMemo2(() =>
|
1819
|
-
|
1820
|
-
|
1821
|
-
|
1822
|
-
|
1823
|
-
|
1824
|
-
|
1825
|
-
|
1826
|
-
|
1827
|
-
|
1828
|
-
|
1829
|
-
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
1837
|
-
|
1838
|
-
|
1839
|
-
|
1840
|
-
|
1841
|
-
|
1842
|
-
|
1843
|
-
|
1844
|
-
|
1845
|
-
|
1846
|
-
|
1858
|
+
const _commandMenu = useMemo2(() => {
|
1859
|
+
return commandMenu({
|
1860
|
+
trigger,
|
1861
|
+
placeholder: placeholder3,
|
1862
|
+
onClose: () => handleOpenChange(false),
|
1863
|
+
onArrowDown: () => {
|
1864
|
+
setCurrentItem((currentItem2) => {
|
1865
|
+
const next = getNextItem(groupsRef.current, currentItem2);
|
1866
|
+
currentRef.current = next;
|
1867
|
+
return next.id;
|
1868
|
+
});
|
1869
|
+
},
|
1870
|
+
onArrowUp: () => {
|
1871
|
+
setCurrentItem((currentItem2) => {
|
1872
|
+
const previous = getPreviousItem(groupsRef.current, currentItem2);
|
1873
|
+
currentRef.current = previous;
|
1874
|
+
return previous.id;
|
1875
|
+
});
|
1876
|
+
},
|
1877
|
+
onEnter: () => {
|
1878
|
+
if (currentRef.current) {
|
1879
|
+
handleSelect(currentRef.current);
|
1880
|
+
}
|
1881
|
+
},
|
1882
|
+
onTextChange: async (trigger2, text) => {
|
1883
|
+
groupsRef.current = await getMenu(trigger2, text);
|
1884
|
+
const firstItem = groupsRef.current.filter((group) => group.items.length > 0)[0]?.items[0];
|
1885
|
+
if (firstItem) {
|
1886
|
+
setCurrentItem(firstItem.id);
|
1887
|
+
currentRef.current = firstItem;
|
1888
|
+
}
|
1889
|
+
refresh({});
|
1847
1890
|
}
|
1848
|
-
|
1849
|
-
|
1850
|
-
}), [
|
1891
|
+
});
|
1892
|
+
}, [
|
1851
1893
|
handleOpenChange,
|
1852
|
-
|
1894
|
+
getMenu,
|
1853
1895
|
serializedTrigger,
|
1854
|
-
|
1896
|
+
placeholder3
|
1855
1897
|
]);
|
1856
1898
|
return {
|
1857
1899
|
commandMenu: _commandMenu,
|
@@ -1866,12 +1908,12 @@ var useCommandMenu = ({ viewRef, trigger, placeholder: placeholder2, getGroups }
|
|
1866
1908
|
};
|
1867
1909
|
|
1868
1910
|
// packages/ui/react-ui-editor/src/extensions/command/typeahead.ts
|
1869
|
-
import { EditorSelection, Prec as
|
1870
|
-
import { Decoration as Decoration6, keymap as keymap5, ViewPlugin as
|
1911
|
+
import { EditorSelection, Prec as Prec3, RangeSetBuilder as RangeSetBuilder4 } from "@codemirror/state";
|
1912
|
+
import { Decoration as Decoration6, keymap as keymap5, ViewPlugin as ViewPlugin8 } from "@codemirror/view";
|
1871
1913
|
var typeahead = ({ onComplete } = {}) => {
|
1872
|
-
let
|
1914
|
+
let hint2;
|
1873
1915
|
const complete = (view) => {
|
1874
|
-
if (!
|
1916
|
+
if (!hint2) {
|
1875
1917
|
return false;
|
1876
1918
|
}
|
1877
1919
|
const selection = view.state.selection.main;
|
@@ -1880,15 +1922,15 @@ var typeahead = ({ onComplete } = {}) => {
|
|
1880
1922
|
{
|
1881
1923
|
from: selection.from,
|
1882
1924
|
to: selection.to,
|
1883
|
-
insert:
|
1925
|
+
insert: hint2
|
1884
1926
|
}
|
1885
1927
|
],
|
1886
|
-
selection: EditorSelection.cursor(selection.from +
|
1928
|
+
selection: EditorSelection.cursor(selection.from + hint2.length)
|
1887
1929
|
});
|
1888
1930
|
return true;
|
1889
1931
|
};
|
1890
1932
|
return [
|
1891
|
-
|
1933
|
+
ViewPlugin8.fromClass(class {
|
1892
1934
|
constructor() {
|
1893
1935
|
this.decorations = Decoration6.none;
|
1894
1936
|
}
|
@@ -1898,12 +1940,12 @@ var typeahead = ({ onComplete } = {}) => {
|
|
1898
1940
|
const line = update2.view.state.doc.lineAt(selection.from);
|
1899
1941
|
if (selection.from === selection.to && selection.from === line.to) {
|
1900
1942
|
const str = update2.state.sliceDoc(line.from, selection.from);
|
1901
|
-
|
1943
|
+
hint2 = onComplete?.({
|
1902
1944
|
line: str
|
1903
1945
|
});
|
1904
|
-
if (
|
1946
|
+
if (hint2) {
|
1905
1947
|
builder.add(selection.from, selection.to, Decoration6.widget({
|
1906
|
-
widget: new Hint(
|
1948
|
+
widget: new Hint(hint2)
|
1907
1949
|
}));
|
1908
1950
|
}
|
1909
1951
|
}
|
@@ -1913,7 +1955,7 @@ var typeahead = ({ onComplete } = {}) => {
|
|
1913
1955
|
decorations: (v) => v.decorations
|
1914
1956
|
}),
|
1915
1957
|
// Keys.
|
1916
|
-
|
1958
|
+
Prec3.highest(keymap5.of([
|
1917
1959
|
{
|
1918
1960
|
key: "Tab",
|
1919
1961
|
preventDefault: true,
|
@@ -1951,16 +1993,16 @@ var matchCompletion = (completion, word) => {
|
|
1951
1993
|
// packages/ui/react-ui-editor/src/extensions/comments.ts
|
1952
1994
|
import { invertedEffects } from "@codemirror/commands";
|
1953
1995
|
import { StateEffect as StateEffect4, StateField as StateField4 } from "@codemirror/state";
|
1954
|
-
import { hoverTooltip, keymap as keymap7, Decoration as Decoration7, EditorView as
|
1996
|
+
import { hoverTooltip, keymap as keymap7, Decoration as Decoration7, EditorView as EditorView11, ViewPlugin as ViewPlugin9 } from "@codemirror/view";
|
1955
1997
|
import sortBy from "lodash.sortby";
|
1956
1998
|
import { useEffect } from "react";
|
1957
1999
|
import { debounce as debounce2 } from "@dxos/async";
|
1958
2000
|
import { log as log4 } from "@dxos/log";
|
1959
|
-
import { isNonNullable } from "@dxos/util";
|
2001
|
+
import { isNonNullable as isNonNullable2 } from "@dxos/util";
|
1960
2002
|
|
1961
2003
|
// packages/ui/react-ui-editor/src/extensions/selection.ts
|
1962
2004
|
import { Transaction } from "@codemirror/state";
|
1963
|
-
import { EditorView as
|
2005
|
+
import { EditorView as EditorView10, keymap as keymap6 } from "@codemirror/view";
|
1964
2006
|
import { debounce } from "@dxos/async";
|
1965
2007
|
import { invariant as invariant3 } from "@dxos/invariant";
|
1966
2008
|
import { isNotFalsy } from "@dxos/util";
|
@@ -1971,7 +2013,7 @@ var createEditorStateTransaction = ({ scrollTo, selection }) => {
|
|
1971
2013
|
return {
|
1972
2014
|
selection,
|
1973
2015
|
scrollIntoView: !scrollTo,
|
1974
|
-
effects: scrollTo ?
|
2016
|
+
effects: scrollTo ? EditorView10.scrollIntoView(scrollTo, {
|
1975
2017
|
yMargin: 96
|
1976
2018
|
}) : void 0,
|
1977
2019
|
annotations: Transaction.userEvent.of(stateRestoreAnnotation)
|
@@ -2013,7 +2055,7 @@ var selectionState = ({ getState, setState } = {}) => {
|
|
2013
2055
|
// setStateDebounced(id, {});
|
2014
2056
|
// },
|
2015
2057
|
// }),
|
2016
|
-
|
2058
|
+
EditorView10.updateListener.of(({ view, transactions }) => {
|
2017
2059
|
const id = view.state.facet(documentId);
|
2018
2060
|
if (!id || transactions.some((tr) => tr.isUserEvent(stateRestoreAnnotation))) {
|
2019
2061
|
return;
|
@@ -2081,7 +2123,7 @@ var commentsState = StateField4.define({
|
|
2081
2123
|
comment,
|
2082
2124
|
range
|
2083
2125
|
};
|
2084
|
-
}).filter(
|
2126
|
+
}).filter(isNonNullable2);
|
2085
2127
|
return {
|
2086
2128
|
...value,
|
2087
2129
|
comments: commentStates
|
@@ -2094,7 +2136,7 @@ var commentsState = StateField4.define({
|
|
2094
2136
|
return value;
|
2095
2137
|
}
|
2096
2138
|
});
|
2097
|
-
var styles2 =
|
2139
|
+
var styles2 = EditorView11.theme({
|
2098
2140
|
".cm-comment, .cm-comment-current": {
|
2099
2141
|
margin: "0 -3px",
|
2100
2142
|
padding: "3px",
|
@@ -2114,7 +2156,7 @@ var createCommentMark = (id, isCurrent) => Decoration7.mark({
|
|
2114
2156
|
"data-comment-id": id
|
2115
2157
|
}
|
2116
2158
|
});
|
2117
|
-
var commentsDecorations =
|
2159
|
+
var commentsDecorations = EditorView11.decorations.compute([
|
2118
2160
|
commentsState
|
2119
2161
|
], (state) => {
|
2120
2162
|
const { selection: { current }, comments: comments2 } = state.field(commentsState);
|
@@ -2133,11 +2175,11 @@ var commentsDecorations = EditorView10.decorations.compute([
|
|
2133
2175
|
}
|
2134
2176
|
const mark = createCommentMark(comment.comment.id, comment.comment.id === current);
|
2135
2177
|
return mark.range(range.from, range.to);
|
2136
|
-
}).filter(
|
2178
|
+
}).filter(isNonNullable2);
|
2137
2179
|
return Decoration7.set(decorations2);
|
2138
2180
|
});
|
2139
2181
|
var commentClickedEffect = StateEffect4.define();
|
2140
|
-
var handleCommentClick =
|
2182
|
+
var handleCommentClick = EditorView11.domEventHandlers({
|
2141
2183
|
click: (event, view) => {
|
2142
2184
|
let target = event.target;
|
2143
2185
|
const editorRoot = view.dom;
|
@@ -2176,7 +2218,7 @@ var trackPastedComments = (onUpdate) => {
|
|
2176
2218
|
}
|
2177
2219
|
};
|
2178
2220
|
return [
|
2179
|
-
|
2221
|
+
EditorView11.domEventHandlers({
|
2180
2222
|
cut: handleTrack,
|
2181
2223
|
copy: handleTrack
|
2182
2224
|
}),
|
@@ -2198,7 +2240,7 @@ var trackPastedComments = (onUpdate) => {
|
|
2198
2240
|
return effects;
|
2199
2241
|
}),
|
2200
2242
|
// Handle paste or the undo of comment deletion.
|
2201
|
-
|
2243
|
+
EditorView11.updateListener.of((update2) => {
|
2202
2244
|
const restore = [];
|
2203
2245
|
for (let i = 0; i < update2.transactions.length; i++) {
|
2204
2246
|
const tr = update2.transactions[i];
|
@@ -2340,7 +2382,7 @@ var comments = (options = {}) => {
|
|
2340
2382
|
//
|
2341
2383
|
// Track deleted ranges and update ranges for decorations.
|
2342
2384
|
//
|
2343
|
-
|
2385
|
+
EditorView11.updateListener.of(({ view, state, changes }) => {
|
2344
2386
|
let mod = false;
|
2345
2387
|
const { comments: comments2, ...value } = state.field(commentsState);
|
2346
2388
|
changes.iterChanges((from, to, from2, to2) => {
|
@@ -2372,7 +2414,7 @@ var comments = (options = {}) => {
|
|
2372
2414
|
//
|
2373
2415
|
// Track selection/proximity.
|
2374
2416
|
//
|
2375
|
-
|
2417
|
+
EditorView11.updateListener.of(({ view, state }) => {
|
2376
2418
|
let min = Infinity;
|
2377
2419
|
const { selection: { current, closest }, comments: comments2 } = state.field(commentsState);
|
2378
2420
|
const { head } = state.selection.main;
|
@@ -2406,7 +2448,7 @@ var comments = (options = {}) => {
|
|
2406
2448
|
}
|
2407
2449
|
}),
|
2408
2450
|
options.onUpdate && trackPastedComments(options.onUpdate)
|
2409
|
-
].filter(
|
2451
|
+
].filter(isNonNullable2);
|
2410
2452
|
};
|
2411
2453
|
var scrollThreadIntoView = (view, id, center = true) => {
|
2412
2454
|
const comment = view.state.field(commentsState).comments.find((range2) => range2.comment.id === id);
|
@@ -2426,7 +2468,7 @@ var scrollThreadIntoView = (view, id, center = true) => {
|
|
2426
2468
|
anchor: range.from
|
2427
2469
|
} : void 0,
|
2428
2470
|
effects: [
|
2429
|
-
needsScroll ?
|
2471
|
+
needsScroll ? EditorView11.scrollIntoView(range.from, center ? {
|
2430
2472
|
y: "center"
|
2431
2473
|
} : void 0) : [],
|
2432
2474
|
needsSelectionUpdate ? setSelection.of({
|
@@ -2456,7 +2498,7 @@ var ExternalCommentSync = class {
|
|
2456
2498
|
this.unsubscribe = subscribe(updateComments);
|
2457
2499
|
}
|
2458
2500
|
};
|
2459
|
-
var createExternalCommentSync = (id, subscribe, getComments) =>
|
2501
|
+
var createExternalCommentSync = (id, subscribe, getComments) => ViewPlugin9.fromClass(class {
|
2460
2502
|
constructor(view) {
|
2461
2503
|
return new ExternalCommentSync(view, id, subscribe, getComments);
|
2462
2504
|
}
|
@@ -2490,8 +2532,8 @@ var debugNodeLogger = (log9 = console.log) => {
|
|
2490
2532
|
};
|
2491
2533
|
|
2492
2534
|
// packages/ui/react-ui-editor/src/extensions/dnd.ts
|
2493
|
-
import { dropCursor, EditorView as
|
2494
|
-
var styles3 =
|
2535
|
+
import { dropCursor, EditorView as EditorView12 } from "@codemirror/view";
|
2536
|
+
var styles3 = EditorView12.theme({
|
2495
2537
|
".cm-dropCursor": {
|
2496
2538
|
borderLeft: "2px solid var(--dx-accentText)",
|
2497
2539
|
color: "var(--dx-accentText)",
|
@@ -2505,7 +2547,7 @@ var dropFile = (options = {}) => {
|
|
2505
2547
|
return [
|
2506
2548
|
styles3,
|
2507
2549
|
dropCursor(),
|
2508
|
-
|
2550
|
+
EditorView12.domEventHandlers({
|
2509
2551
|
drop: (event, view) => {
|
2510
2552
|
event.preventDefault();
|
2511
2553
|
const files = event.dataTransfer?.files;
|
@@ -2532,7 +2574,7 @@ import { bracketMatching, defaultHighlightStyle, syntaxHighlighting } from "@cod
|
|
2532
2574
|
import { searchKeymap } from "@codemirror/search";
|
2533
2575
|
import { EditorState } from "@codemirror/state";
|
2534
2576
|
import { oneDarkHighlightStyle } from "@codemirror/theme-one-dark";
|
2535
|
-
import { EditorView as
|
2577
|
+
import { EditorView as EditorView15, ViewPlugin as ViewPlugin10, drawSelection, dropCursor as dropCursor2, highlightActiveLine, keymap as keymap8, lineNumbers, placeholder as placeholder2, scrollPastEnd } from "@codemirror/view";
|
2536
2578
|
import defaultsDeep2 from "lodash.defaultsdeep";
|
2537
2579
|
import merge from "lodash.merge";
|
2538
2580
|
import { generateName } from "@dxos/display-name";
|
@@ -2541,7 +2583,7 @@ import { hexToHue, isNotFalsy as isNotFalsy2 } from "@dxos/util";
|
|
2541
2583
|
|
2542
2584
|
// packages/ui/react-ui-editor/src/extensions/focus.ts
|
2543
2585
|
import { StateEffect as StateEffect5, StateField as StateField6 } from "@codemirror/state";
|
2544
|
-
import { EditorView as
|
2586
|
+
import { EditorView as EditorView13 } from "@codemirror/view";
|
2545
2587
|
var focusEffect = StateEffect5.define();
|
2546
2588
|
var focusField = StateField6.define({
|
2547
2589
|
create: () => false,
|
@@ -2556,7 +2598,7 @@ var focusField = StateField6.define({
|
|
2556
2598
|
});
|
2557
2599
|
var focus = [
|
2558
2600
|
focusField,
|
2559
|
-
|
2601
|
+
EditorView13.domEventHandlers({
|
2560
2602
|
focus: (event, view) => {
|
2561
2603
|
setTimeout(() => view.dispatch({
|
2562
2604
|
effects: focusEffect.of(true)
|
@@ -2571,7 +2613,7 @@ var focus = [
|
|
2571
2613
|
];
|
2572
2614
|
|
2573
2615
|
// packages/ui/react-ui-editor/src/defaults.ts
|
2574
|
-
import { EditorView as
|
2616
|
+
import { EditorView as EditorView14 } from "@codemirror/view";
|
2575
2617
|
import { mx as mx2 } from "@dxos/react-ui-theme";
|
2576
2618
|
|
2577
2619
|
// packages/ui/react-ui-editor/src/styles/markdown.ts
|
@@ -2825,20 +2867,19 @@ var editorSlots = {
|
|
2825
2867
|
className: editorWidth
|
2826
2868
|
}
|
2827
2869
|
};
|
2828
|
-
var editorGutter =
|
2870
|
+
var editorGutter = EditorView14.theme({
|
2829
2871
|
".cm-gutters": {
|
2830
2872
|
background: "var(--dx-baseSurface)",
|
2831
2873
|
paddingRight: "1rem"
|
2832
2874
|
}
|
2833
2875
|
});
|
2834
|
-
var editorMonospace =
|
2876
|
+
var editorMonospace = EditorView14.theme({
|
2835
2877
|
".cm-content": {
|
2836
2878
|
fontFamily: fontMono
|
2837
2879
|
}
|
2838
2880
|
});
|
2839
2881
|
var editorWithToolbarLayout = "grid grid-cols-1 grid-rows-[min-content_1fr] data-[toolbar=disabled]:grid-rows-[1fr] justify-center content-start overflow-hidden";
|
2840
2882
|
var stackItemContentEditorClassNames = (role) => mx2("attention-surface dx-focus-ring-inset data-[toolbar=disabled]:pbs-2", role === "section" ? "[&_.cm-scroller]:overflow-hidden [&_.cm-scroller]:min-bs-24" : "min-bs-0");
|
2841
|
-
var stackItemContentToolbarClassNames = (role) => mx2("relative z-[1] flex is-full bg-toolbarSurface border-be border-subduedSeparator", role === "section" && "sticky block-start-0 -mbe-px min-is-0");
|
2842
2883
|
|
2843
2884
|
// packages/ui/react-ui-editor/src/extensions/factories.ts
|
2844
2885
|
var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/factories.ts";
|
@@ -2864,7 +2905,7 @@ var createBasicExtensions = (_props) => {
|
|
2864
2905
|
const props = defaultsDeep2({}, _props, defaultBasicOptions);
|
2865
2906
|
return [
|
2866
2907
|
// NOTE: Doesn't catch errors in keymap functions.
|
2867
|
-
|
2908
|
+
EditorView15.exceptionSink.of((err) => {
|
2868
2909
|
log5.catch(err, void 0, {
|
2869
2910
|
F: __dxlog_file8,
|
2870
2911
|
L: 100,
|
@@ -2879,7 +2920,7 @@ var createBasicExtensions = (_props) => {
|
|
2879
2920
|
props.drawSelection && drawSelection({
|
2880
2921
|
cursorBlinkRate: 1200
|
2881
2922
|
}),
|
2882
|
-
props.editable !== void 0 &&
|
2923
|
+
props.editable !== void 0 && EditorView15.editable.of(props.editable),
|
2883
2924
|
props.focus && focus,
|
2884
2925
|
props.highlightActiveLine && highlightActiveLine(),
|
2885
2926
|
props.history && history(),
|
@@ -2887,9 +2928,9 @@ var createBasicExtensions = (_props) => {
|
|
2887
2928
|
lineNumbers(),
|
2888
2929
|
editorGutter
|
2889
2930
|
],
|
2890
|
-
props.lineWrapping &&
|
2931
|
+
props.lineWrapping && EditorView15.lineWrapping,
|
2891
2932
|
props.monospace && editorMonospace,
|
2892
|
-
props.placeholder &&
|
2933
|
+
props.placeholder && placeholder2(props.placeholder),
|
2893
2934
|
props.readOnly !== void 0 && EditorState.readOnly.of(props.readOnly),
|
2894
2935
|
props.scrollPastEnd && scrollPastEnd(),
|
2895
2936
|
props.tabSize && EditorState.tabSize.of(props.tabSize),
|
@@ -2925,17 +2966,17 @@ var defaultThemeSlots = {
|
|
2925
2966
|
var createThemeExtensions = ({ themeMode, styles: styles4, syntaxHighlighting: _syntaxHighlighting, slots: _slots } = {}) => {
|
2926
2967
|
const slots = defaultsDeep2({}, _slots, defaultThemeSlots);
|
2927
2968
|
return [
|
2928
|
-
|
2929
|
-
|
2969
|
+
EditorView15.darkTheme.of(themeMode === "dark"),
|
2970
|
+
EditorView15.baseTheme(styles4 ? merge({}, defaultTheme, styles4) : defaultTheme),
|
2930
2971
|
// https://github.com/codemirror/theme-one-dark
|
2931
2972
|
_syntaxHighlighting && (themeMode === "dark" ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle)),
|
2932
|
-
slots.editor?.className &&
|
2973
|
+
slots.editor?.className && EditorView15.editorAttributes.of({
|
2933
2974
|
class: slots.editor.className
|
2934
2975
|
}),
|
2935
|
-
slots.content?.className &&
|
2976
|
+
slots.content?.className && EditorView15.contentAttributes.of({
|
2936
2977
|
class: slots.content.className
|
2937
2978
|
}),
|
2938
|
-
slots.scroll?.className &&
|
2979
|
+
slots.scroll?.className && ViewPlugin10.fromClass(class {
|
2939
2980
|
constructor(view) {
|
2940
2981
|
view.scrollDOM.classList.add(slots.scroll.className);
|
2941
2982
|
}
|
@@ -2966,7 +3007,7 @@ var createDataExtensions = ({ id, text, space, identity }) => {
|
|
2966
3007
|
|
2967
3008
|
// packages/ui/react-ui-editor/src/extensions/folding.tsx
|
2968
3009
|
import { codeFolding, foldGutter } from "@codemirror/language";
|
2969
|
-
import { EditorView as
|
3010
|
+
import { EditorView as EditorView16 } from "@codemirror/view";
|
2970
3011
|
import React2 from "react";
|
2971
3012
|
import { Icon } from "@dxos/react-ui";
|
2972
3013
|
var folding = (_props = {}) => [
|
@@ -2990,7 +3031,7 @@ var folding = (_props = {}) => [
|
|
2990
3031
|
}));
|
2991
3032
|
}
|
2992
3033
|
}),
|
2993
|
-
|
3034
|
+
EditorView16.theme({
|
2994
3035
|
".cm-foldGutter": {
|
2995
3036
|
opacity: 0.3,
|
2996
3037
|
transition: "opacity 0.3s",
|
@@ -3003,7 +3044,7 @@ var folding = (_props = {}) => [
|
|
3003
3044
|
];
|
3004
3045
|
|
3005
3046
|
// packages/ui/react-ui-editor/src/extensions/hashtag.tsx
|
3006
|
-
import { Decoration as Decoration8, EditorView as
|
3047
|
+
import { Decoration as Decoration8, EditorView as EditorView17, MatchDecorator, ViewPlugin as ViewPlugin11, WidgetType as WidgetType4 } from "@codemirror/view";
|
3007
3048
|
import { getHashColor, mx as mx3 } from "@dxos/react-ui-theme";
|
3008
3049
|
var TagWidget = class extends WidgetType4 {
|
3009
3050
|
constructor(_text) {
|
@@ -3023,7 +3064,7 @@ var tagMatcher = new MatchDecorator({
|
|
3023
3064
|
})
|
3024
3065
|
});
|
3025
3066
|
var hashtag = () => [
|
3026
|
-
|
3067
|
+
ViewPlugin11.fromClass(class {
|
3027
3068
|
constructor(view) {
|
3028
3069
|
this.tags = tagMatcher.createDeco(view);
|
3029
3070
|
}
|
@@ -3032,11 +3073,11 @@ var hashtag = () => [
|
|
3032
3073
|
}
|
3033
3074
|
}, {
|
3034
3075
|
decorations: (instance) => instance.tags,
|
3035
|
-
provide: (plugin) =>
|
3076
|
+
provide: (plugin) => EditorView17.atomicRanges.of((view) => {
|
3036
3077
|
return view.plugin(plugin)?.tags || Decoration8.none;
|
3037
3078
|
})
|
3038
3079
|
}),
|
3039
|
-
|
3080
|
+
EditorView17.theme({
|
3040
3081
|
".cm-tag": {
|
3041
3082
|
borderRadius: "4px",
|
3042
3083
|
marginRight: "6px",
|
@@ -3091,14 +3132,14 @@ var schemaLinter = (validate) => (view) => {
|
|
3091
3132
|
};
|
3092
3133
|
|
3093
3134
|
// packages/ui/react-ui-editor/src/extensions/listener.ts
|
3094
|
-
import { EditorView as
|
3135
|
+
import { EditorView as EditorView18 } from "@codemirror/view";
|
3095
3136
|
var listener = ({ onFocus, onChange }) => {
|
3096
3137
|
const extensions = [];
|
3097
|
-
onFocus && extensions.push(
|
3138
|
+
onFocus && extensions.push(EditorView18.focusChangeEffect.of((_, focusing) => {
|
3098
3139
|
onFocus(focusing);
|
3099
3140
|
return null;
|
3100
3141
|
}));
|
3101
|
-
onChange && extensions.push(
|
3142
|
+
onChange && extensions.push(EditorView18.updateListener.of((update2) => {
|
3102
3143
|
onChange(update2.state.doc.toString(), update2.state.facet(documentId));
|
3103
3144
|
}));
|
3104
3145
|
return extensions;
|
@@ -3108,7 +3149,7 @@ var listener = ({ onFocus, onChange }) => {
|
|
3108
3149
|
import { snippet } from "@codemirror/autocomplete";
|
3109
3150
|
import { syntaxTree as syntaxTree2 } from "@codemirror/language";
|
3110
3151
|
import { EditorSelection as EditorSelection2 } from "@codemirror/state";
|
3111
|
-
import { EditorView as
|
3152
|
+
import { EditorView as EditorView19, keymap as keymap9 } from "@codemirror/view";
|
3112
3153
|
import { useMemo as useMemo3 } from "react";
|
3113
3154
|
var formattingEquals = (a, b) => a.blockType === b.blockType && a.strong === b.strong && a.emphasis === b.emphasis && a.strikethrough === b.strikethrough && a.code === b.code && a.link === b.link && a.listStyle === b.listStyle && a.blockQuote === b.blockQuote;
|
3114
3155
|
var Inline = /* @__PURE__ */ function(Inline2) {
|
@@ -4197,7 +4238,7 @@ var getFormatting = (state) => {
|
|
4197
4238
|
};
|
4198
4239
|
};
|
4199
4240
|
var useFormattingState = (state) => {
|
4200
|
-
return useMemo3(() =>
|
4241
|
+
return useMemo3(() => EditorView19.updateListener.of((update2) => {
|
4201
4242
|
if (update2.docChanged || update2.selectionSet) {
|
4202
4243
|
Object.entries(getFormatting(update2.state)).forEach(([key, active]) => {
|
4203
4244
|
state[key] = active;
|
@@ -4261,7 +4302,6 @@ import { defaultKeymap as defaultKeymap2, indentWithTab as indentWithTab2 } from
|
|
4261
4302
|
import { markdownLanguage as markdownLanguage3, markdown } from "@codemirror/lang-markdown";
|
4262
4303
|
import { syntaxHighlighting as syntaxHighlighting2 } from "@codemirror/language";
|
4263
4304
|
import { languages } from "@codemirror/language-data";
|
4264
|
-
import { lintKeymap } from "@codemirror/lint";
|
4265
4305
|
import { keymap as keymap10 } from "@codemirror/view";
|
4266
4306
|
import { isNotFalsy as isNotFalsy3 } from "@dxos/util";
|
4267
4307
|
|
@@ -4474,8 +4514,7 @@ var createMarkdownExtensions = (options = {}) => {
|
|
4474
4514
|
options.indentWithTab !== false && indentWithTab2,
|
4475
4515
|
// https://codemirror.net/docs/ref/#commands.defaultKeymap
|
4476
4516
|
...defaultKeymap2,
|
4477
|
-
...completionKeymap2
|
4478
|
-
...lintKeymap
|
4517
|
+
...completionKeymap2
|
4479
4518
|
].filter(isNotFalsy3))
|
4480
4519
|
];
|
4481
4520
|
};
|
@@ -4510,16 +4549,16 @@ var convertTreeToJson = (state) => {
|
|
4510
4549
|
// packages/ui/react-ui-editor/src/extensions/markdown/decorate.ts
|
4511
4550
|
import { syntaxTree as syntaxTree7 } from "@codemirror/language";
|
4512
4551
|
import { RangeSetBuilder as RangeSetBuilder6, StateEffect as StateEffect6 } from "@codemirror/state";
|
4513
|
-
import { EditorView as
|
4552
|
+
import { EditorView as EditorView23, Decoration as Decoration11, WidgetType as WidgetType7, ViewPlugin as ViewPlugin13 } from "@codemirror/view";
|
4514
4553
|
import { invariant as invariant4 } from "@dxos/invariant";
|
4515
4554
|
import { mx as mx4 } from "@dxos/react-ui-theme";
|
4516
4555
|
|
4517
4556
|
// packages/ui/react-ui-editor/src/extensions/markdown/changes.ts
|
4518
4557
|
import { syntaxTree as syntaxTree4 } from "@codemirror/language";
|
4519
4558
|
import { Transaction as Transaction2 } from "@codemirror/state";
|
4520
|
-
import { ViewPlugin as
|
4559
|
+
import { ViewPlugin as ViewPlugin12 } from "@codemirror/view";
|
4521
4560
|
var adjustChanges = () => {
|
4522
|
-
return
|
4561
|
+
return ViewPlugin12.fromClass(class {
|
4523
4562
|
update(update2) {
|
4524
4563
|
const tree = syntaxTree4(update2.state);
|
4525
4564
|
const adjustments = [];
|
@@ -4661,7 +4700,7 @@ var getValidUrl = (str) => {
|
|
4661
4700
|
// packages/ui/react-ui-editor/src/extensions/markdown/image.ts
|
4662
4701
|
import { syntaxTree as syntaxTree5 } from "@codemirror/language";
|
4663
4702
|
import { StateField as StateField8 } from "@codemirror/state";
|
4664
|
-
import { Decoration as Decoration9, EditorView as
|
4703
|
+
import { Decoration as Decoration9, EditorView as EditorView20, WidgetType as WidgetType5 } from "@codemirror/view";
|
4665
4704
|
var image = (_options = {}) => {
|
4666
4705
|
return [
|
4667
4706
|
StateField8.define({
|
@@ -4689,7 +4728,7 @@ var image = (_options = {}) => {
|
|
4689
4728
|
add: buildDecorations(from, to, tr.state)
|
4690
4729
|
});
|
4691
4730
|
},
|
4692
|
-
provide: (field) =>
|
4731
|
+
provide: (field) => EditorView20.decorations.from(field)
|
4693
4732
|
})
|
4694
4733
|
];
|
4695
4734
|
};
|
@@ -4748,10 +4787,10 @@ var ImageWidget = class extends WidgetType5 {
|
|
4748
4787
|
};
|
4749
4788
|
|
4750
4789
|
// packages/ui/react-ui-editor/src/extensions/markdown/styles.ts
|
4751
|
-
import { EditorView as
|
4790
|
+
import { EditorView as EditorView21 } from "@codemirror/view";
|
4752
4791
|
var bulletListIndentationWidth = 24;
|
4753
4792
|
var orderedListIndentationWidth = 36;
|
4754
|
-
var formattingStyles =
|
4793
|
+
var formattingStyles = EditorView21.theme({
|
4755
4794
|
/**
|
4756
4795
|
* Horizontal rule.
|
4757
4796
|
*/
|
@@ -4873,12 +4912,12 @@ var formattingStyles = EditorView20.theme({
|
|
4873
4912
|
// packages/ui/react-ui-editor/src/extensions/markdown/table.ts
|
4874
4913
|
import { syntaxTree as syntaxTree6 } from "@codemirror/language";
|
4875
4914
|
import { RangeSetBuilder as RangeSetBuilder5, StateField as StateField9 } from "@codemirror/state";
|
4876
|
-
import { Decoration as Decoration10, EditorView as
|
4915
|
+
import { Decoration as Decoration10, EditorView as EditorView22, WidgetType as WidgetType6 } from "@codemirror/view";
|
4877
4916
|
var table = (options = {}) => {
|
4878
4917
|
return StateField9.define({
|
4879
4918
|
create: (state) => update(state, options),
|
4880
4919
|
update: (_, tr) => update(tr.state, options),
|
4881
|
-
provide: (field) =>
|
4920
|
+
provide: (field) => EditorView22.decorations.from(field)
|
4882
4921
|
});
|
4883
4922
|
};
|
4884
4923
|
var update = (state, _options) => {
|
@@ -5379,7 +5418,7 @@ var buildDecorations2 = (view, options, focus2) => {
|
|
5379
5418
|
var forceUpdate = StateEffect6.define();
|
5380
5419
|
var decorateMarkdown = (options = {}) => {
|
5381
5420
|
return [
|
5382
|
-
|
5421
|
+
ViewPlugin13.fromClass(class {
|
5383
5422
|
constructor(view) {
|
5384
5423
|
({ deco: this.deco, atomicDeco: this.atomicDeco } = buildDecorations2(view, options, view.hasFocus));
|
5385
5424
|
}
|
@@ -5411,9 +5450,9 @@ var decorateMarkdown = (options = {}) => {
|
|
5411
5450
|
}
|
5412
5451
|
}, {
|
5413
5452
|
provide: (plugin) => [
|
5414
|
-
|
5415
|
-
|
5416
|
-
|
5453
|
+
EditorView23.atomicRanges.of((view) => view.plugin(plugin)?.atomicDeco ?? Decoration11.none),
|
5454
|
+
EditorView23.decorations.of((view) => view.plugin(plugin)?.atomicDeco ?? Decoration11.none),
|
5455
|
+
EditorView23.decorations.of((view) => view.plugin(plugin)?.deco ?? Decoration11.none)
|
5417
5456
|
]
|
5418
5457
|
}),
|
5419
5458
|
image(),
|
@@ -5658,6 +5697,7 @@ var traverse = (root, cb) => {
|
|
5658
5697
|
return value;
|
5659
5698
|
}
|
5660
5699
|
}
|
5700
|
+
return void 0;
|
5661
5701
|
};
|
5662
5702
|
return t(root, root.type === "root" ? -1 : 0);
|
5663
5703
|
};
|
@@ -5715,7 +5755,7 @@ var outlinerTree = (options = {}) => {
|
|
5715
5755
|
case "BulletList": {
|
5716
5756
|
invariant5(current, void 0, {
|
5717
5757
|
F: __dxlog_file11,
|
5718
|
-
L:
|
5758
|
+
L: 219,
|
5719
5759
|
S: void 0,
|
5720
5760
|
A: [
|
5721
5761
|
"current",
|
@@ -5732,7 +5772,7 @@ var outlinerTree = (options = {}) => {
|
|
5732
5772
|
case "ListItem": {
|
5733
5773
|
invariant5(parent, void 0, {
|
5734
5774
|
F: __dxlog_file11,
|
5735
|
-
L:
|
5775
|
+
L: 228,
|
5736
5776
|
S: void 0,
|
5737
5777
|
A: [
|
5738
5778
|
"parent",
|
@@ -5774,7 +5814,7 @@ var outlinerTree = (options = {}) => {
|
|
5774
5814
|
case "ListMark": {
|
5775
5815
|
invariant5(current, void 0, {
|
5776
5816
|
F: __dxlog_file11,
|
5777
|
-
L:
|
5817
|
+
L: 272,
|
5778
5818
|
S: void 0,
|
5779
5819
|
A: [
|
5780
5820
|
"current",
|
@@ -5788,7 +5828,7 @@ var outlinerTree = (options = {}) => {
|
|
5788
5828
|
case "Task": {
|
5789
5829
|
invariant5(current, void 0, {
|
5790
5830
|
F: __dxlog_file11,
|
5791
|
-
L:
|
5831
|
+
L: 278,
|
5792
5832
|
S: void 0,
|
5793
5833
|
A: [
|
5794
5834
|
"current",
|
@@ -5801,7 +5841,7 @@ var outlinerTree = (options = {}) => {
|
|
5801
5841
|
case "TaskMarker": {
|
5802
5842
|
invariant5(current, void 0, {
|
5803
5843
|
F: __dxlog_file11,
|
5804
|
-
L:
|
5844
|
+
L: 283,
|
5805
5845
|
S: void 0,
|
5806
5846
|
A: [
|
5807
5847
|
"current",
|
@@ -5817,7 +5857,7 @@ var outlinerTree = (options = {}) => {
|
|
5817
5857
|
if (node.name === "BulletList") {
|
5818
5858
|
invariant5(parent, void 0, {
|
5819
5859
|
F: __dxlog_file11,
|
5820
|
-
L:
|
5860
|
+
L: 291,
|
5821
5861
|
S: void 0,
|
5822
5862
|
A: [
|
5823
5863
|
"parent",
|
@@ -5831,7 +5871,7 @@ var outlinerTree = (options = {}) => {
|
|
5831
5871
|
});
|
5832
5872
|
invariant5(tree, void 0, {
|
5833
5873
|
F: __dxlog_file11,
|
5834
|
-
L:
|
5874
|
+
L: 298,
|
5835
5875
|
S: void 0,
|
5836
5876
|
A: [
|
5837
5877
|
"tree",
|
@@ -6121,18 +6161,18 @@ var commands = () => keymap12.of([
|
|
6121
6161
|
]);
|
6122
6162
|
|
6123
6163
|
// packages/ui/react-ui-editor/src/extensions/outliner/outliner.ts
|
6124
|
-
import { Prec as
|
6125
|
-
import { Decoration as Decoration12, EditorView as
|
6164
|
+
import { Prec as Prec4 } from "@codemirror/state";
|
6165
|
+
import { Decoration as Decoration12, EditorView as EditorView24, ViewPlugin as ViewPlugin15 } from "@codemirror/view";
|
6126
6166
|
import { mx as mx5 } from "@dxos/react-ui-theme";
|
6127
6167
|
|
6128
6168
|
// packages/ui/react-ui-editor/src/extensions/outliner/editor.ts
|
6129
6169
|
import { EditorSelection as EditorSelection4, EditorState as EditorState2 } from "@codemirror/state";
|
6130
|
-
import { ViewPlugin as
|
6170
|
+
import { ViewPlugin as ViewPlugin14 } from "@codemirror/view";
|
6131
6171
|
import { log as log7 } from "@dxos/log";
|
6132
6172
|
var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/outliner/editor.ts";
|
6133
6173
|
var LIST_ITEM_REGEX = /^\s*- (\[ \]|\[x\])? /;
|
6134
6174
|
var initialize = () => {
|
6135
|
-
return
|
6175
|
+
return ViewPlugin14.fromClass(class {
|
6136
6176
|
constructor(view) {
|
6137
6177
|
const first = view.state.doc.lineAt(0);
|
6138
6178
|
const text = view.state.sliceDoc(first.from, first.to);
|
@@ -6317,7 +6357,7 @@ var editor = () => [
|
|
6317
6357
|
// packages/ui/react-ui-editor/src/extensions/outliner/outliner.ts
|
6318
6358
|
var outliner = (options = {}) => [
|
6319
6359
|
// Commands.
|
6320
|
-
|
6360
|
+
Prec4.highest(commands()),
|
6321
6361
|
// Selection.
|
6322
6362
|
selectionCompartment.of(selectionFacet.of([])),
|
6323
6363
|
// State.
|
@@ -6333,12 +6373,12 @@ var outliner = (options = {}) => [
|
|
6333
6373
|
listPaddingLeft: 8
|
6334
6374
|
}),
|
6335
6375
|
// Researve space for menu.
|
6336
|
-
|
6376
|
+
EditorView24.contentAttributes.of({
|
6337
6377
|
class: "is-full !mr-[3rem]"
|
6338
6378
|
})
|
6339
6379
|
];
|
6340
6380
|
var decorations = () => [
|
6341
|
-
|
6381
|
+
ViewPlugin15.fromClass(class {
|
6342
6382
|
constructor(view) {
|
6343
6383
|
this.decorations = Decoration12.none;
|
6344
6384
|
this.updateDecorations(view.state, view);
|
@@ -6373,7 +6413,7 @@ var decorations = () => [
|
|
6373
6413
|
decorations: (v) => v.decorations
|
6374
6414
|
}),
|
6375
6415
|
// Theme.
|
6376
|
-
|
6416
|
+
EditorView24.theme(Object.assign({
|
6377
6417
|
".cm-list-item": {
|
6378
6418
|
borderLeftWidth: "1px",
|
6379
6419
|
borderRightWidth: "1px",
|
@@ -6410,7 +6450,7 @@ var decorations = () => [
|
|
6410
6450
|
import "@dxos/lit-ui/dx-ref-tag.pcss";
|
6411
6451
|
import { syntaxTree as syntaxTree10 } from "@codemirror/language";
|
6412
6452
|
import { RangeSetBuilder as RangeSetBuilder7, StateField as StateField11 } from "@codemirror/state";
|
6413
|
-
import { Decoration as Decoration13, EditorView as
|
6453
|
+
import { Decoration as Decoration13, EditorView as EditorView25, WidgetType as WidgetType8 } from "@codemirror/view";
|
6414
6454
|
var preview = (options = {}) => {
|
6415
6455
|
return [
|
6416
6456
|
// NOTE: Atomic block decorations must be created from a state field, now a widget, otherwise it results in the following error:
|
@@ -6419,16 +6459,9 @@ var preview = (options = {}) => {
|
|
6419
6459
|
create: (state) => buildDecorations3(state, options),
|
6420
6460
|
update: (_, tr) => buildDecorations3(tr.state, options),
|
6421
6461
|
provide: (field) => [
|
6422
|
-
|
6423
|
-
|
6462
|
+
EditorView25.decorations.from(field),
|
6463
|
+
EditorView25.atomicRanges.of((view) => view.state.field(field))
|
6424
6464
|
]
|
6425
|
-
}),
|
6426
|
-
EditorView24.theme({
|
6427
|
-
".cm-preview-block": {
|
6428
|
-
"--dx-card-spacing-inline": "var(--dx-trimMd)",
|
6429
|
-
"--dx-card-spacing-block": "var(--dx-trimMd)",
|
6430
|
-
marginInline: "calc(-1*var(--dx-trimMd))"
|
6431
|
-
}
|
6432
6465
|
})
|
6433
6466
|
];
|
6434
6467
|
};
|
@@ -6469,7 +6502,7 @@ var buildDecorations3 = (state, options) => {
|
|
6469
6502
|
//
|
6470
6503
|
case "Image": {
|
6471
6504
|
const link = getLinkRef(state, node.node);
|
6472
|
-
if (options.
|
6505
|
+
if (options.addBlockContainer && options.removeBlockContainer && link) {
|
6473
6506
|
builder.add(node.from, node.to, Decoration13.replace({
|
6474
6507
|
block: true,
|
6475
6508
|
// atomic: true,
|
@@ -6512,50 +6545,13 @@ var PreviewBlockWidget = class extends WidgetType8 {
|
|
6512
6545
|
}
|
6513
6546
|
toDOM(view) {
|
6514
6547
|
const root = document.createElement("div");
|
6515
|
-
root.classList.add("cm-preview-block");
|
6516
|
-
|
6517
|
-
const pos = view.posAtDOM(root);
|
6518
|
-
const node = syntaxTree10(view.state).resolve(pos + 1).node.parent;
|
6519
|
-
if (!node) {
|
6520
|
-
return;
|
6521
|
-
}
|
6522
|
-
const link = getLinkRef(view.state, node);
|
6523
|
-
if (link?.ref !== action.link.ref) {
|
6524
|
-
return;
|
6525
|
-
}
|
6526
|
-
switch (action.type) {
|
6527
|
-
// TODO(burdon): Should we dispatch to the view or mutate the document? (i.e., handle externally?)
|
6528
|
-
// Insert ref text.
|
6529
|
-
case "insert": {
|
6530
|
-
view.dispatch({
|
6531
|
-
changes: {
|
6532
|
-
from: node.from,
|
6533
|
-
to: node.to,
|
6534
|
-
insert: action.target.text
|
6535
|
-
}
|
6536
|
-
});
|
6537
|
-
break;
|
6538
|
-
}
|
6539
|
-
// Remove ref.
|
6540
|
-
case "delete": {
|
6541
|
-
view.dispatch({
|
6542
|
-
changes: {
|
6543
|
-
from: node.from,
|
6544
|
-
to: node.to
|
6545
|
-
}
|
6546
|
-
});
|
6547
|
-
break;
|
6548
|
-
}
|
6549
|
-
}
|
6550
|
-
};
|
6551
|
-
this._options.renderBlock(root, {
|
6552
|
-
readonly: view.state.readOnly,
|
6553
|
-
link: this._link,
|
6554
|
-
onAction: handleAction,
|
6555
|
-
onLookup: this._options.onLookup
|
6556
|
-
}, view);
|
6548
|
+
root.classList.add("cm-preview-block", "density-coarse");
|
6549
|
+
this._options.addBlockContainer?.(this._link, root);
|
6557
6550
|
return root;
|
6558
6551
|
}
|
6552
|
+
destroy() {
|
6553
|
+
this._options.removeBlockContainer?.(this._link);
|
6554
|
+
}
|
6559
6555
|
};
|
6560
6556
|
|
6561
6557
|
// packages/ui/react-ui-editor/src/extensions/typewriter.ts
|
@@ -6996,20 +6992,15 @@ var EditorToolbar = /* @__PURE__ */ memo(({ classNames, attendableId, role, ...p
|
|
6996
6992
|
var _effect = _useSignals();
|
6997
6993
|
try {
|
6998
6994
|
const menuProps = useEditorToolbarActionGraph(props);
|
6999
|
-
return /* @__PURE__ */ React3.createElement(
|
7000
|
-
role: "none",
|
7001
|
-
className: stackItemContentToolbarClassNames(role)
|
7002
|
-
}, /* @__PURE__ */ React3.createElement(ElevationProvider, {
|
6995
|
+
return /* @__PURE__ */ React3.createElement(ElevationProvider, {
|
7003
6996
|
elevation: role === "section" ? "positioned" : "base"
|
7004
6997
|
}, /* @__PURE__ */ React3.createElement(MenuProvider, {
|
7005
6998
|
...menuProps,
|
7006
6999
|
attendableId
|
7007
7000
|
}, /* @__PURE__ */ React3.createElement(ToolbarMenu, {
|
7008
|
-
classNames
|
7009
|
-
|
7010
|
-
|
7011
|
-
]
|
7012
|
-
}))));
|
7001
|
+
classNames,
|
7002
|
+
textBlockWidth: true
|
7003
|
+
})));
|
7013
7004
|
} finally {
|
7014
7005
|
_effect.f();
|
7015
7006
|
}
|
@@ -7295,7 +7286,10 @@ var RefPopover = /* @__PURE__ */ forwardRef(({ children, open, onOpenChange, mod
|
|
7295
7286
|
try {
|
7296
7287
|
const [rootRef, setRootRef] = useState2(null);
|
7297
7288
|
useEffect3(() => {
|
7298
|
-
|
7289
|
+
if (!rootRef || !onActivate) {
|
7290
|
+
return;
|
7291
|
+
}
|
7292
|
+
return addEventListener2(rootRef, "dx-ref-tag-activate", onActivate, customEventOptions);
|
7299
7293
|
}, [
|
7300
7294
|
rootRef,
|
7301
7295
|
onActivate
|
@@ -7404,7 +7398,10 @@ var RefDropdownMenuProvider = ({ children, onLookup }) => {
|
|
7404
7398
|
onLookup
|
7405
7399
|
]);
|
7406
7400
|
useEffect4(() => {
|
7407
|
-
|
7401
|
+
if (!rootRef) {
|
7402
|
+
return;
|
7403
|
+
}
|
7404
|
+
return addEventListener3(rootRef, "dx-ref-tag-activate", handleDxRefTagActivate, customEventOptions2);
|
7408
7405
|
}, [
|
7409
7406
|
rootRef
|
7410
7407
|
]);
|
@@ -7432,7 +7429,7 @@ var RefDropdownMenu = {
|
|
7432
7429
|
|
7433
7430
|
// packages/ui/react-ui-editor/src/hooks/useTextEditor.ts
|
7434
7431
|
import { EditorState as EditorState3 } from "@codemirror/state";
|
7435
|
-
import { EditorView as
|
7432
|
+
import { EditorView as EditorView26 } from "@codemirror/view";
|
7436
7433
|
import { useFocusableGroup } from "@fluentui/react-tabster";
|
7437
7434
|
import { useCallback as useCallback5, useEffect as useEffect5, useMemo as useMemo5, useRef as useRef5, useState as useState4 } from "react";
|
7438
7435
|
import { log as log8 } from "@dxos/log";
|
@@ -7476,7 +7473,7 @@ var useTextEditor = (props = {}, deps = []) => {
|
|
7476
7473
|
id && documentId.of(id),
|
7477
7474
|
extensions,
|
7478
7475
|
// NOTE: This doesn't catch errors in keymap functions.
|
7479
|
-
|
7476
|
+
EditorView26.exceptionSink.of((err) => {
|
7480
7477
|
log8.catch(err, void 0, {
|
7481
7478
|
F: __dxlog_file13,
|
7482
7479
|
L: 97,
|
@@ -7486,10 +7483,10 @@ var useTextEditor = (props = {}, deps = []) => {
|
|
7486
7483
|
})
|
7487
7484
|
].filter(isNotFalsy4)
|
7488
7485
|
});
|
7489
|
-
view2 = new
|
7486
|
+
view2 = new EditorView26({
|
7490
7487
|
parent: parentRef.current,
|
7491
7488
|
state,
|
7492
|
-
scrollTo: scrollTo ?
|
7489
|
+
scrollTo: scrollTo ? EditorView26.scrollIntoView(scrollTo, {
|
7493
7490
|
yMargin: 96
|
7494
7491
|
}) : void 0,
|
7495
7492
|
dispatchTransactions: debug ? debugDispatcher : void 0
|
@@ -7589,7 +7586,7 @@ export {
|
|
7589
7586
|
EditorInputModes,
|
7590
7587
|
EditorState4 as EditorState,
|
7591
7588
|
EditorToolbar,
|
7592
|
-
|
7589
|
+
EditorView27 as EditorView,
|
7593
7590
|
EditorViewMode,
|
7594
7591
|
EditorViewModes,
|
7595
7592
|
Inline,
|
@@ -7664,6 +7661,7 @@ export {
|
|
7664
7661
|
formattingKeymap,
|
7665
7662
|
getFormatting,
|
7666
7663
|
getItem,
|
7664
|
+
getLinkRef,
|
7667
7665
|
getListItemContent,
|
7668
7666
|
getNextItem,
|
7669
7667
|
getPreviousItem,
|
@@ -7689,7 +7687,6 @@ export {
|
|
7689
7687
|
mention,
|
7690
7688
|
moveItemDown,
|
7691
7689
|
moveItemUp,
|
7692
|
-
multilinePlaceholder,
|
7693
7690
|
openCommand,
|
7694
7691
|
openEffect,
|
7695
7692
|
outliner,
|
@@ -7713,7 +7710,6 @@ export {
|
|
7713
7710
|
setStyle,
|
7714
7711
|
singleValueFacet,
|
7715
7712
|
stackItemContentEditorClassNames,
|
7716
|
-
stackItemContentToolbarClassNames,
|
7717
7713
|
staticCompletion,
|
7718
7714
|
table,
|
7719
7715
|
tags2 as tags,
|